home *** CD-ROM | disk | FTP | other *** search
/ Champak 40 / Vol 40.iso / games / super_su.swf / scripts / DefineSprite_606 / frame_1 / DoAction.as
Encoding:
Text File  |  2007-04-19  |  4.8 KB  |  211 lines

  1. function mKill()
  2. {
  3.    this._parent.mKillObject(this);
  4. }
  5. function mPhysics(interval)
  6. {
  7.    var newPosX = this.intPosX + this.intVelX * interval;
  8.    var newPosY = this.intPosY + this.intVelY * interval;
  9.    this.intPosX = newPosX;
  10.    this.intPosY = newPosY;
  11. }
  12. function mReset()
  13. {
  14.    this.oWave = this._parent.oWave;
  15.    this.intPosX = 0;
  16.    this.intPosY = -10;
  17.    this.intVelX = 0;
  18.    this.intVelY = 0;
  19.    this.intGravity = -1;
  20.    this.strmedia = "wave";
  21.    this.intAngle = 0;
  22.    this.strMode = "paddling";
  23.    this.intMaxVel = 30;
  24.    this.hexColorRopa = this._parent.hexColorRopa;
  25.    this.hexColorTabla = this._parent.hexColorTabla;
  26. }
  27. function mStepFrame(interval)
  28. {
  29.    this.mGetMedia();
  30.    this.mTestCollisions();
  31.    if(this.strmedia == "air")
  32.    {
  33.       this.intVelY += this.intGravity * interval;
  34.    }
  35.    if(this.strmedia == "wave")
  36.    {
  37.       var absVel = Math.sqrt(this.intVelX * this.intVelX + this.intVelY * this.intVelY);
  38.       if(Math.sin(this.intAngle) < 0)
  39.       {
  40.          absVel *= 1 - Math.sin(this.intAngle) / 50;
  41.       }
  42.       else
  43.       {
  44.          absVel *= 0.999;
  45.       }
  46.       this.intVelX = absVel * Math.cos(this.intAngle);
  47.       this.intVelY = absVel * Math.sin(this.intAngle);
  48.    }
  49.    this.SpeedLimit();
  50.    this.mPhysics(interval);
  51. }
  52. function SpeedLimit()
  53. {
  54.    if(this.intVelX > this.intMaxVel)
  55.    {
  56.       this.intVelX = this.intMaxVel;
  57.    }
  58.    if(this.intVelX < - this.intMaxVel)
  59.    {
  60.       this.intVelX = - this.intMaxVel;
  61.    }
  62. }
  63. function mGetMedia()
  64. {
  65.    if(this.intPosY > 0)
  66.    {
  67.       if(this.strmedia == "wave")
  68.       {
  69.          this.intAccAngle = 0;
  70.       }
  71.       this.strmedia = "air";
  72.    }
  73.    else if(this.intPosY > this.oWave.mGetGround())
  74.    {
  75.       if(this.strmedia == "air")
  76.       {
  77.          if(Math.sin(this.intAngle) >= 0)
  78.          {
  79.             this.strmedia = "missed";
  80.          }
  81.          else
  82.          {
  83.             var vueltas = Math.floor(Math.abs(this.intAccAngle / 3.141592653589793));
  84.             if(vueltas > 0)
  85.             {
  86.                var score = 100 * (vueltas * vueltas);
  87.                this._parent.mNewScore(score,this.intPosX,0,506);
  88.             }
  89.             this.strmedia = "wave";
  90.          }
  91.       }
  92.       else
  93.       {
  94.          this.strmedia = "wave";
  95.       }
  96.    }
  97.    else
  98.    {
  99.       this.strmedia = "ground";
  100.    }
  101. }
  102. function mTestCollisions()
  103. {
  104.    if(this.intPosX < this.oWave.intPosX)
  105.    {
  106.       this.mCollide("wave");
  107.    }
  108.    if(this.strmedia == "ground")
  109.    {
  110.       this.mCollide("ground");
  111.    }
  112.    if(this.strmedia == "missed")
  113.    {
  114.       this.mCollide("missed");
  115.    }
  116.    if(this.intPosX > this.oWave.intFinish)
  117.    {
  118.       this._parent.mJumpLevel();
  119.    }
  120. }
  121. function mLooseLife()
  122. {
  123.    this.oImage.mSetPose("fall");
  124.    this.sndVida.start();
  125.    this._parent.mLooseLife();
  126. }
  127. function mCollide(strID)
  128. {
  129.    if(strID == "wave")
  130.    {
  131.       this.sndOla.start();
  132.       this.mLooseLife();
  133.    }
  134.    if(strID == "ground")
  135.    {
  136.       this.mLooseLife();
  137.    }
  138.    if(strID == "missed")
  139.    {
  140.       this.mLooseLife();
  141.    }
  142.    if(strID == "obst")
  143.    {
  144.       this.oImage.mSetPose("hit");
  145.       this.sndObstaculo.start();
  146.       if(this.intVelX > 0)
  147.       {
  148.          this.intVelX = 10;
  149.       }
  150.       else
  151.       {
  152.          this.intVelX = -10;
  153.       }
  154.    }
  155.    if(strID == "bomb")
  156.    {
  157.       this.mLooseLife();
  158.    }
  159.    if(strID == "life")
  160.    {
  161.       this._parent._parent.mAddLife();
  162.       this._parent.vidasdisplay.mRefresh();
  163.    }
  164. }
  165. function mRotate(aint)
  166. {
  167.    this.intAngle += aint;
  168.    this.intAccAngle += aint;
  169.    if(this.intAngle > 6.283185307179586)
  170.    {
  171.       while(this.intAngle > 6.283185307179586)
  172.       {
  173.          this.intAngle -= 6.283185307179586;
  174.       }
  175.    }
  176.    if(this.intAngle < -6.283185307179586)
  177.    {
  178.       while(this.intAngle < -6.283185307179586)
  179.       {
  180.          this.intAngle += 6.283185307179586;
  181.       }
  182.    }
  183. }
  184. function mGetPoints()
  185. {
  186.    var intLargo = 65;
  187.    var pto = new Object();
  188.    pto.x = this.intPosX;
  189.    pto.y = this.intPosY;
  190.    var arrPnts = new Array();
  191.    ppto.x = 0.1 * intLargo * Math.cos(this.intAngle) + pto.x;
  192.    ppto.y = 0.1 * intLargo * Math.sin(this.intAngle) + pto.y;
  193.    arrPnts.push(ppto);
  194.    ppto = new Object();
  195.    ppto.x = 0.8 * intLargo * Math.cos(this.intAngle) + pto.x;
  196.    ppto.y = 0.8 * intLargo * Math.sin(this.intAngle) + pto.y;
  197.    arrPnts.push(ppto);
  198.    ppto = new Object();
  199.    ppto.x = 0.5 * intLargo * Math.cos(this.intAngle) + pto.x;
  200.    ppto.y = 0.5 * intLargo * Math.sin(this.intAngle) + pto.y;
  201.    arrPnts.push(ppto);
  202.    return arrPnts;
  203. }
  204. this.sndObstaculo = new Sound(this);
  205. this.sndObstaculo.attachSound("obstaculo1.wav");
  206. this.sndOla = new Sound(this);
  207. this.sndOla.attachSound("ola.wav");
  208. this.sndVida = new Sound(this);
  209. this.sndVida.attachSound("vida.wav");
  210. this.mReset();
  211.